//
//  MyView.swift
//  skincare
//
//  Created by whu125 on 2023/5/10.
//

import SwiftUI

struct MyView: View {
    
    let user_name: String = "不懒宁"
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    
    var body: some View {
        FullScreenStack{
            
            ZStack{
                HStack{
                    VStack(alignment: .leading, spacing: 20){
                        Image("icon")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 100)
                        Text("Hi, \(user_name)")
                            .foregroundColor(Color.white)
                            .font(.system(size: 20))
                            .padding(.bottom, 30)
                        
                        navigateView(iconName: "person.2", text: "我的好友", jumpView: EmptyView())
                            .offset(x:-2)
                        navigateView(iconName: "wand.and.stars", text: "肤质变化", jumpView: EmptyView())
                            .offset(x:3)
                        navigateView(iconName: "clock.arrow.circlepath", text: "测一测历史", jumpView: EmptyView())
                            .offset(x:2)
                        navigateView(iconName: "list.clipboard", text: "计划", jumpView: EmptyView())
                            .offset(x:3)
                        navigateView(iconName: "star", text: "我的收藏", jumpView: EmptyView())
                        navigateView(iconName: "gearshape", text: "设置", jumpView: EmptyView())
                        navigateView(iconName: "rectangle.portrait.and.arrow.right", text: "登出", jumpView: EmptyView())
                        
                    }
                    .offset(x:20, y:-130)
                    
                    ZStack(alignment: .trailing) {
                        
                        Rectangle()
                            .fill(Color.white.opacity(0.2))
                            .frame(width: 300, height:550)
                            .cornerRadius(20)
                            .rotationEffect(Angle.degrees(-10))
                            .offset(x: 50, y: -50)
                        
                        Rectangle()
                            .fill(Color.white.opacity(0.4))
                            .frame(width: 300, height:600)
                            .cornerRadius(20)
                            .rotationEffect(Angle.degrees(-10))
                            .offset(x: 75, y: -50)
                        
                        Rectangle()
                        
                            .frame(width: 300, height:650)
                            .overlay(
                                Image("index")
                                    .resizable()
                                    .aspectRatio(contentMode: .fill)
                                    .onTapGesture {
                                        self.presentationMode.wrappedValue.dismiss()
                                    }
                                )
                            .cornerRadius(20)
                            .rotationEffect(Angle.degrees(-10))
                            .offset(x: 100, y: -50)
                            
                        
                        
                    }
                    .frame(width: 220, height: 600)
                    .offset(x: 60, y: -20)
                    
                    
                }
                
                Image("loginPicture")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 320)
                    .offset(x: -50, y: 280)
            }
            
        }
        .background(Color(red: 0.10, green: 0.83, blue: 0.64))
        .navigationBarBackButtonHidden(true)
        
    }
    
    // 跳转函数
    func navigateView<destination: View>(iconName: String, text: String, jumpView: destination) -> some View {
        
        return NavigationLink(
            destination: jumpView,
            label: {
                HStack{
                    Image(systemName: iconName)
                        .foregroundColor(Color.white)
                        .font(.system(size: 18))
                    
                    Text(text)
                        .foregroundColor(Color.white)
                        .font(.system(size: 18))
                }
            })
    }
    
    
}

struct MyView_Previews: PreviewProvider {
    static var previews: some View {
        MyView()
    }
}
